package agentFramework.strategy;

import java.util.ArrayList;
import java.util.Random;

import agentFramework.action.Action;
import agentFramework.agent.Agent;
import agentFramework.core.env.Environment;

public class EpsQLStrategy extends Strategy
{
	private QLStrategy		qlStrategy;
	private double			epsilon;


	public EpsQLStrategy(Environment env, Agent owner, double epsilon, double alpha, double defaultPenalty)
	{
		super(env, owner);
		
		this.qlStrategy = new QLStrategy(env, owner, alpha, defaultPenalty);
	}

	@Override
	public void init() 
	{
		qlStrategy.init();
	}

	@Override
	public Action makeDecision() 
	{
		ArrayList<Action> 	actionList = environment.getPossibleActionList();
		Random				r = new Random();
		Action 				action = null;
		
		
		if (r.nextDouble() < epsilon)
		{
			// with epsilon probability get a random action
			action = actionList.get( r.nextInt(actionList.size()) );
		}
		else
		{
			// with 1-epsilon probability use the QL strategy
			action = qlStrategy.makeDecision();
		}
		
		return action;
	}

	@Override
	public void reviseStrategy() 
	{
		qlStrategy.reviseStrategy();
	}

}
